package com.snail.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.snail.model.dto.VideoWatchRequest;
import com.snail.response.BaseResponse;
import com.snail.service.BizUserTaskRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: cwl
 * @Description: 系统任务接口。用户完成任务获得积分
 * @DateTime : 2025/7/23 20:10
 **/
@RestController
@RequestMapping("/task")
public class TaskActionController {

    @Autowired
    private BizUserTaskRecordService bizUserTaskRecordService;

    // 签到接口
    @PostMapping("/sign-in")
    public BaseResponse<?> signIn() {
        //获取登入用户id。satoken 获取当前用户id
        Integer userId = StpUtil.getLoginIdAsInt();
        return bizUserTaskRecordService.signIn(Long.valueOf(userId));
    }

    // 查询当前用户积分记录、总积分、本月获得
    @GetMapping("/points-record")
    public BaseResponse<?> getUserPointsRecord() {
        Integer userId = StpUtil.getLoginIdAsInt();
        return bizUserTaskRecordService.getUserPointsRecord(Long.valueOf(userId));
    }

    // 查询某月每日积分/任务完成情况
    @GetMapping("/calendar-records")
    public BaseResponse<?> getUserCalendarRecords(
            @RequestParam(required = false) String month // 格式: 2025-07
    ) {
        Long userId = Long.valueOf(StpUtil.getLoginIdAsInt());
        return bizUserTaskRecordService.getUserCalendarRecords(userId, month);
    }



    @PostMapping("/video-watch")
    public BaseResponse<?> awardVideoWatchPoints(@RequestBody VideoWatchRequest request) {
        return bizUserTaskRecordService.awardVideoWatchPoints(request);
    }

    // 积分订阅接口，使用后端写死的taskId
    @PostMapping("/subscribe")
    public BaseResponse<?> subscribeTask(@RequestParam Long teamId) {
        long userId = StpUtil.getLoginIdAsLong();
        return bizUserTaskRecordService.subscribeTask(userId,teamId);
    }



}
